/**
 * Created by huangxiaolu on 2014/10/10.
 */
var mysql = require('mysql');
var pool = mysql.createPool({
    host: 'localhost',
    user: 'root',
    password: 'P@ssw0rd',
    port: '3306',
    database: 'test',
    maximumpoolsize:'2000'
})

var Sequelize = require('sequelize')
    , sequelize = new Sequelize('test', 'root', 'P@ssw0rd', {
        dialect: 'mysql', // or 'sqlite', 'postgres', 'mariadb'
        host:'arch-lpt-win-03.qa.nt.ctripcorp.com',
        port:   3306, // or 5432 (for postgres)
        pool: {
            maxConnections: 2000
        }
    });
sequelize
    .authenticate()
    .complete(function(err) {
        if (!!err) {
            console.log('Unable to connect to the database:', err)
        } else {
            console.log('Connection has been established successfully.')
        }
    });
var Mytasks=sequelize.define('Mytasks',{
    id:Sequelize.INTEGER,
    Title:Sequelize.STRING
},{
    tableName:'mytasks',
    timestamps:false
});

function createLog(resp,logTable) {
    /*var connection = mysql.createConnection({
        host: 'arch-lpt-win-03.qa.nt.ctripcorp.com',
        user: 'root',
        password: 'P@ssw0rd',
        port: '3306',
        database: 'test',
        maximumpoolsize:'2000'
    });mysql.createConnection({
        host: 'pub.mysql.db.fat.qa.nt.ctripcorp.com',
        user: 'us_test_huangxl',
        password: 'P@ssw0rd',
        port: '55666',
        database: 'ttdorderdb'
    });

    connection.connect();*/

    pool.getConnection(function (err, connection) {
    var logSql = 'insert into '+logTable + '(orderid,content) values(1,\'some logs\')';//'SELECT * from ord_order limit 10'
    connection.query(logSql, function (err, rows, fields) {
        if (err) console.log(err);
        //console.log('The orders is: ', rows);
        resp.send(rows);
    });

    connection.release();


    });

}
function showTask(res)
{
    Mytasks.find({limit:100}).success(function(tasks) {
        res.send(tasks);
    });
}

exports.createLog=createLog;
exports.showTask=showTask;